<template>
  <div class="box">
    <img class='bg' src="../../assets/img/login/bg.png" alt="">
    <div class="con">
      <div class="ultab flex vc ha">
        <div class="li" :class="tab==1?'act':''" @click='tab=1'>登录</div>
        <div class="li" :class="tab==2?'act':''" @click='tab=2'>注册</div>
      </div>
      <div class="conul" v-if='tab==1'>
        <div class="li flex vc">
          <img class='tel' src="../../assets/img/login/tel.png" alt="">
          <input type="number" v-model="registeredUser.username" placeholder="请输入您的手机号">
        </div>
        <div class="li flex vc">
          <img class='mima' src="../../assets/img/login/mima.png" alt="">
          <input type="text" v-model="registeredUser.password" placeholder="请输入您的密码">
        </div>
        <button class='submit margin120' @click="login">登录</button>
      </div>
      <div class="conul reg" v-if='tab==2'>
        <div class="li">
          <input type="number" v-model="registeredUser.mobileNumber" placeholder="请输入您的手机号">
        </div>
        <div class="li flex vc hb">
          <input type="text" v-model="registeredUser.alumna" placeholder="校友">
        </div>
        <div class="li">
          <input type="text" v-model="registeredUser.nickname" placeholder="姓名">
        </div>
        <div class="li">
          <input type="text" v-model="registeredUser.companyName" placeholder="单位名称">
        </div>
        <div class="li">
          <input type="text" v-model="registeredUser.position" placeholder="职务">
        </div>
        <div class="li">
          <input type="text"  v-model="registeredUser.password" placeholder="设置密码">
        </div>
        <div class="li">
          <input type="text"  v-model="registeredUser.password1" placeholder="确认密码">
        </div>
        <button class='submit' @click="registered">注册</button>
      </div>
    </div>
    <van-popup v-model="popup" position="bottom">
      <van-picker show-toolbar :columns="slots" @cancel="popup = !popup" @confirm="onConfirm"/>
    </van-popup>
  </div>
</template>

<script>
import { List, Cell } from 'vant'
import { registered, login } from '@/api/login'
import { setAdminToken } from '@/utils/auth'

export default {
  components: {
    [List.name]: List,
    [Cell.name]: Cell
  },
  data () {
    return {
      tab: 1,
      popup: false,
      slots: ['普票', '增值税发票'],
      type: '',
      registeredUser: {
        alumna: false
      }
    }
  },
  methods: {
    onConfirm (picker, values) {
      this.type = picker
      this.popup = false
    },
    registered () {
      registered(this.registeredUser).then(response => {
        this.tab = 1
      })
    },
    login () {
      login(this.registeredUser).then(response => {
        setAdminToken(response.data.token)
        this.$router.push({ path: '/news' })
      })
    }
  }
}
</script>

<style scoped="scoped">
  .box {
    font-size: 17px;
    position: relative;
  }

  .bg {
    width: 100%;
  }

  .con {
    position: absolute;
    top: 180px;
    left: 50%;
    margin-left: -175px;
    width: 350px;
  }

  .ultab {
    padding: 0 30px;
    color: rgba(255, 255, 255, 0.56);
  }

  .ultab .act {
    color: #fff;
  }

  .ultab .li {
    padding: 10px 30px 20px;
  }

  .conul {
    width: 100%;
    height: calc(100vh - 233px);
    background: #fff;
    border-radius: 10px;
    padding: 0 20px;
    overflow-y: scroll;
  }

  .conul::-webkit-scrollbar {
    display: none;
  }

  .conul .li {
    font-size: 15px;
    padding: 30px 5px 15px;
    width: 100%;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  }

  .conul.reg .li {
    padding: 25px 5px 15px;
  }

  .conul .li .tel {
    width: 15px;
    height: 19px;
    margin-right: 10px;
  }

  .conul .li .mima {
    width: 15px;
    height: 16px;
    margin-right: 10px;
  }

  .submit {
    display: block;
    width: 100%;
    height: 50px;
    background: #8C2E27;
    color: #fff;
    border-radius: 100px;
    margin: 30px auto;
    text-align: center;
    line-height: 50px;
    font-size: 18px;
    box-shadow: 0px 8px 15px 0px rgba(0, 0, 0, 0.15);
  }

  .conul .submit.margin120 {
    margin: 120px auto 0;
  }

  .pic {
    width: calc(100% - 10px);
  }

  .back {
    width: 8px;
    height: 16px;
  }
</style>
